package com.j2eefast.bussiness.contract.service;


import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.j2eefast.bussiness.contract.entity.BusDepreciationEntity;
import com.j2eefast.bussiness.contract.entity.BusEquipmentEntity;
import com.j2eefast.bussiness.contract.mapper.BusDepreciationMapper;
import com.j2eefast.bussiness.contract.mapper.BusEquipmentMapper;
import com.j2eefast.common.core.page.Query;
import com.j2eefast.common.core.utils.PageUtil;
import com.j2eefast.framework.annotation.DataFilter;
import com.j2eefast.framework.sys.entity.SysUserEntity;
import com.j2eefast.framework.utils.Constant;
import com.j2eefast.framework.utils.UserUtils;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;


/**
 * <p>折旧管理</p>
 *
 * @author: summer
 * @date: 2021-05-31 14:41
 * @web: http://www.letukeji.cn
 * @version: 1.0.1
 */

@Service
public class BusDepreciationService extends ServiceImpl<BusDepreciationMapper, BusDepreciationEntity> {

    @Resource
    protected BusDepreciationMapper busDepreciationMapper;


    /**
     * 页面展示查询翻页
     */
    public PageUtil findPage(Map<String, Object> params) {
		String department = (String) params.get("department");
        String department2 = (String) params.get("department2");
        String equipmentCode = (String) params.get("equipmentCode");
        String equipmentCode2 = (String) params.get("equipmentCode2");
        String equipmentName = (String) params.get("equipmentName");
        String equipmentModel = (String) params.get("equipmentModel");
        String jingcanValue = (String) params.get("jingcanValue");
        String age = (String) params.get("age");
        String equipmentValue = (String) params.get("equipmentValue");
        String worthValue = (String) params.get("worthValue");
        String worth = (String) params.get("worth");
        String monthDepreciation = (String) params.get("monthDepreciation");
        String totalDepreciation = (String) params.get("totalDepreciation");
        String beginTime = (String) params.get("beginTime");
        String endTime = (String) params.get("endTime");
        Page<BusDepreciationEntity> page = busDepreciationMapper.findPage(
                new Query<BusDepreciationEntity>(params).getPage(),
				StrUtil.nullToDefault(department,""),
                StrUtil.nullToDefault(department2,""),
                StrUtil.nullToDefault(equipmentCode,""),
                StrUtil.nullToDefault(equipmentCode2,""),
                StrUtil.nullToDefault(equipmentName,""),
                StrUtil.nullToDefault(equipmentModel,""),
                StrUtil.nullToDefault(jingcanValue,""),
                StrUtil.nullToDefault(age,""),
                StrUtil.nullToDefault(equipmentValue,""),
                StrUtil.nullToDefault(worthValue,""),
                StrUtil.nullToDefault(worth,""),
                StrUtil.nullToDefault(monthDepreciation,""),
                StrUtil.nullToDefault(totalDepreciation,""),
                StrUtil.nullToDefault(beginTime,""),
                StrUtil.nullToDefault(endTime,""),
                (String) params.get(Constant.SQL_FILTER));
        return new PageUtil(page);
    }

    public boolean deleteByIds(Long[] ids) {

        return busDepreciationMapper.deleteByIds(ids);

    }

    public boolean updateCheck(Long id) {
        Long userId= UserUtils.getUserInfo().getId();

        return busDepreciationMapper.updateCheck(id ,userId);

    }
    public SysUserEntity getSysById(@Param("userId")Long userId){
        return busDepreciationMapper.getSysById(userId);
    }

    public List<BusDepreciationEntity> findList(Map<String, Object> params) {
//        String name = (String) params.get("name");
//        String ceoName = (String) params.get("ceoName");
//        String paymentNuit = (String) params.get("paymentNuit");
//        String contractSum = (String) params.get("contractSum");
//        String projectName = (String) params.get("projectName");
        Long[] ids  = (Long[]) params.get("ids");
        return busDepreciationMapper.findList(
//                StrUtil.nullToDefault(name,""),
//                StrUtil.nullToDefault(ceoName,""),
//                StrUtil.nullToDefault(paymentNuit,""),
//                StrUtil.nullToDefault(projectName,""),
//                StrUtil.nullToDefault(contractSum,""),
                ids,
                (String) params.get(Constant.SQL_FILTER));
    }

    public int getDepreciationInfo(String equipmentCode) {
        BusDepreciationEntity busDepreciationEntity = busDepreciationMapper.getDepreciationInfo(equipmentCode);
        if(busDepreciationEntity!=null){
            return 1;
        }else
            return 0;
    }

//    public int getDepreciationInfo(String name){
//
//        BusDepreciationEntity b= busDepreciationMapper.getDepreciationInfo(name);
//        if(b!=null){
//            return 1;
//        }else
//            return 0;
//
//    }




}
